import { WeaSearchGroup,WeaFormItem } from 'ecCom';
import { observer} from 'mobx-react';
import {WeaSwitch} from 'comsMobx';
import * as mobx from 'mobx'

@observer
class Condition extends React.Component{
	
	render(){
		const { conditionRp,formRp} = this.props;		       
        let conditions = [];
        let formParams = {};
        let isFormInit = formRp.isFormInit;
        conditions = mobx.toJS(conditionRp);
        formParams = formRp.getFormParams(); 

        let group = [];
        isFormInit && conditions.map((c,index) =>{
            let items = [];
            c.items.map((fields, idx) => {  
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@49gezr@${fields.domkey[0]}`}
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        error={formRp.getError(fields)}
                        tipPosition="bottom"
                        wrapperCol={{span: `${fields.fieldcol}`}}>
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@relj18@${fields.domkey[0]}`} fieldConfig={fields} form={formRp} />  
                        </WeaFormItem>),
                    colSpan:1,
                })
            });

            group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@6c1l1a@${index}`} needTigger={true} showGroup={c.defaultshow} items={items}  col={1}/>)
        });

        return <div>{group}</div>;
	}
}

export {Condition}